package com.latvia.utils;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.R.array;

import com.latvia.model.Recipe;

public class JsonParser {

	public static final String kImage = "image";
	public static final String kTitle = "title";
	public static final String kId = "id";

	public static ArrayList<Recipe> parseAllRecipes(JSONArray jsonArray)
			throws JSONException, UnsupportedEncodingException {

		ArrayList<Recipe> recipes = new ArrayList<Recipe>();

		for (int i = 0; i < jsonArray.length(); i++) {
			JSONObject obj = jsonArray.getJSONObject(i);
			Recipe recipe = new Recipe();
			recipe.setName(obj.getString(Constants.kRecipeName));
			recipe.setCategoryId(Integer.parseInt(obj.getString("id")));
			JSONObject category = obj.getJSONObject("category");
			recipe.setCategoryId(category.getInt("id"));
			recipe.setExperience(obj.getInt(Constants.kExperience));
			recipe.setDescription(obj.getString(Constants.kDescription));
			//recipe.setImageURL(obj.getString(Constants.kRecipeImageURL));
			recipe.setId(obj.getInt("id"));
			
			recipes.add(recipe);
		}

		return recipes;
	}
	
	
	
}
